#include <kore/kore.h>
#include <kore/http.h>
#include "head/lately_week.h"

int
statis_week(struct http_request *req)
{
    FILE *fp = fopen("/hihttps/log/stat_week.log", "r");
    fseek(fp, 0, SEEK_END);
    char* text;
    long lSize = ftell(fp);
    // 用完后需要将内存free掉
    text=(char*)malloc(lSize+1);
    rewind(fp);
    fread(text,sizeof(char),lSize,fp);
    text[lSize] = '\0';
    fclose(fp);
    free(text);
    kore_log(LOG_NOTICE, "text: %s", text);

    struct kore_buf	*buf;

    buf = kore_buf_alloc(32);
    kore_buf_appendf(buf, "[");
    kore_buf_appendf(buf, "%s", text);
    kore_buf_appendf(buf, "]");
    http_response_header(req, "content-type", "text/json");
    http_response(req, 200, buf->data, buf->offset);
    return (KORE_RESULT_OK);
}